import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * 数据范围164ms - 450ms， 每个对应的聚合数 >= 30
 */
public class Reader {
    public static void main(String[] args) throws Exception {
        String path = "/Users/bytedance/Desktop/清洗后数据.txt";
        FileReader in = new FileReader(path);
        BufferedReader buffer = new BufferedReader(in);
        String line;
        Map<Integer, Integer> phiMap = new HashMap<>();
        while ((line = buffer.readLine()) != null) {
            String[] split = line.trim().split("\\s+");
            int phi = Integer.parseInt(split[0]);
            phi = phi / 1000;
            phiMap.put(phi, phiMap.getOrDefault(phi, 0) + 1);
        }
        buffer.close();
        int i = 0;
        StringBuffer sb = new StringBuffer();
        sb.append("聚合相位差").append("\t").append("实验次数").append("\r\n");
        for (Map.Entry<Integer, Integer> entry : phiMap.entrySet()) {
            if((i++ % 10) == 0){
                System.out.println();
            }
            if(entry.getValue() < 30) throw new RuntimeException("the data invalid");
            sb.append("\t").append(entry.getKey()).append("\t\t\t\t").append(entry.getValue()).append("\r\n");
            System.out.print(entry.getKey()+" : "+entry.getValue()+"  ");
        }

        path = "/Users/bytedance/Desktop/stat.txt";
        FileWriter out = new FileWriter(path);
        BufferedWriter writer = new BufferedWriter(out);
        writer.write(sb.toString());
        writer.flush();
        writer.close();
    }
}
